package cn.qrx.gateway.seesion.defaults;

import cn.qrx.gateway.datasource.DataSource;
import cn.qrx.gateway.datasource.DataSourceFactory;
import cn.qrx.gateway.datasource.unpooled.UnpooledDataSourceFactory;
import cn.qrx.gateway.seesion.Configuration;
import cn.qrx.gateway.seesion.GatewaySession;
import cn.qrx.gateway.seesion.GatewaySessionFactory;

/**
 * @Author: 屈燃希
 * @Date:   2025/10/15
 * @Version: V1.0
 * @Description:
 */
public class DefaultGatewaySessionFactory implements GatewaySessionFactory {

    private final Configuration configuration;

    public DefaultGatewaySessionFactory(Configuration configuration) {
        this.configuration = configuration;
    }

    @Override
    public GatewaySession openSession(String uri) {

        DataSourceFactory dataSourceFactory = new UnpooledDataSourceFactory();
        dataSourceFactory.setProperties(configuration, uri);
        DataSource dataSource = dataSourceFactory.getDataSource();
        return new DefaultGatewaySession(configuration,uri, dataSource);
    }

}
